package com.example.javaserve.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.javaserve.entity.SysUser;
import com.example.javaserve.entity.UserBaseInfo;
import com.example.javaserve.mapper.SysUserMapper;
import com.example.javaserve.mapper.UserBaseInfoMapper;
import com.example.javaserve.result.Result;
import com.example.javaserve.result.impl.ErrorResult;
import com.example.javaserve.result.impl.SuccessResult;
import com.example.javaserve.service.UserBaseInfoService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.ws.Action;
import java.util.List;

/**
 * @projectName: my_project
 * @package: com.example.javaserve.service.impl
 * @className: UserBaseInfoServiceImpl
 * @author: xxXPCSC
 * @description: TODO
 * @date: 2023/11/17 15:36
 * @version: 1.0
 **/
@Service
public class UserBaseInfoServiceImpl extends ServiceImpl<UserBaseInfoMapper, UserBaseInfo>  implements UserBaseInfoService {

    @Autowired
    private UserBaseInfoMapper userBaseInfoMapper;

    @Override
    public UserBaseInfo getByUsername(String username) {
        return this.getOne(new LambdaQueryWrapper<UserBaseInfo>().eq(UserBaseInfo::getInfoUsername,username));
    }

    @Override
    public String getUserRoleInfo(String username) {
        UserBaseInfo userBaseInfo = getByUsername(username);
        return userBaseInfo.getInfoRole();
    }

    @Override
    public Result<UserBaseInfo> getAllNormalUser(int current, int size) {
        QueryWrapper<UserBaseInfo> o = new QueryWrapper<UserBaseInfo>();
        o.select("info_id","info_username","info_email","info_sex","info_role").eq("info_role","normal");
        IPage<UserBaseInfo> page = new Page<>(current, size);
        IPage<UserBaseInfo> userBaseInfoIPage = userBaseInfoMapper.selectPage(page, o);
        List<UserBaseInfo> records = userBaseInfoIPage.getRecords();
        return new SuccessResult<>(records);
    }


}
